/**
 * 
 */
package org.karthik.ecomm.util;

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;

/**
 * @author Uday Shankar
 * 
 */
public class ECommSessionFactory {

	// This is the singleton instance
	private static ECommSessionFactory instance = null;

	private static SessionFactory factory;

	private ECommSessionFactory() {

		Configuration cfg = new Configuration().configure("ECommerce.cfg.xml");
		StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
		StandardServiceRegistry serviceRegistry = builder.build();
		factory = cfg.buildSessionFactory(serviceRegistry);
	}
	
	public synchronized static ECommSessionFactory getInstance(){
		
		if(instance==null){
			instance = new ECommSessionFactory();
		}
		return instance;
	}

	public synchronized SessionFactory getFactory(){
		return factory;
	}
}
